<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/vue.js"></script>
</head>
<body>
    <div id="app">
        <h3>父组件</h3>
        <p>msg:{{ msg }}</p>
        <input type="text" v-model="msg">
        <hr>
        <comp-a :msg="msg" @update-msg="updateMsg"></comp-a>
    </div>

    <template id="tempa">
        <div>
            <h3>子组件</h3>
            <p>msg:{{ msg }}</p>
            <input type="text" v-model="msg">
            <hr>
            <input type="text" :value="msg" @input="sendMsg($event.target.value)">
            <hr>
            <input type="text" v-model="getMsg">

        </div>
    </template>
</body>
<script>
    new Vue({
        el:'#app',
        data:{
            msg:"字符串"
        },
        methods: {
            updateMsg(arg){
                this.msg = arg;
            }
        },
        components:{
            CompA:{
                template:"#tempa",
                props:["msg"],
                computed: {
                    getMsg:{
                        get(){
                            return this.msg;
                        },
                        set(nv){
                            this.$emit("update-msg",nv)
                        }
                    }
                },
                methods: {
                    sendMsg(nv){
                        this.$emit("update-msg",nv)
                    }
                },
            }
        }
    });
</script>
</html>